package me.zhengjie.modules.system.service.apply;

import cn.hutool.json.JSONUtil;
import me.zhengjie.exception.CommonUtilException;
import me.zhengjie.modules.system.enums.ApplyWorkOrderTypeEnum;
import me.zhengjie.modules.system.service.DisPartnerService;
import me.zhengjie.modules.system.service.dto.DisChangeApplyDto;
import me.zhengjie.modules.system.service.dto.DisPartnerWorkOrderDto;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class DisPartnerDelServiceImpl implements IApplyCallbackService{

    @Autowired
    DisPartnerService disPartnerService;

    @Override
    public Integer getApplyType() {
        return ApplyWorkOrderTypeEnum.DelPartner.getType();
    }

    @Override
    public boolean execute(DisChangeApplyDto applyDto) {
        String json = applyDto.getApplyContent();
        if(StringUtils.isEmpty(json)){
           throw new CommonUtilException("申请内容不能为空");
        }
        DisPartnerWorkOrderDto disPartnerWorkOrderDto = JSONUtil.toBean(json, DisPartnerWorkOrderDto.class);
        if(Objects.isNull(disPartnerWorkOrderDto.getPartnerId())){
            throw new CommonUtilException("城市合伙人ID不能为空");
        }
        try {
            disPartnerService.deleteAll(new Long[]{disPartnerWorkOrderDto.getPartnerId()});
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
}
